package com.jly.service.impl;

import com.jly.service.MissileService;
import com.jly.vos.ApiResult;
import com.jly.vos.GuidanceDataVo;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.net.URI;

/**
 * @author Liwenhao
 * @date 2022/3/24 14:21
 * @description
 */
@Service("missileServiceConsulImpl")
@Slf4j
public class MissileServiceConsulImpl implements MissileService {
    @Autowired
    private RestTemplate restTemplate;

    private final String RADAR = "consul-provider-radar-8085";

    @SneakyThrows
    @Override
    public ApiResult fire(GuidanceDataVo request) {
        log.info("[发射导弹]" + request.toString());
        URI uri = new URI("http://" + RADAR + "/radar/detect/" + request.getId());
        ApiResult<String> apiResult = restTemplate.getForObject(uri, ApiResult.class);
        return apiResult;
    }
}
